<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Metasploit Terminal</title>
    <style>
        html,
        body {
        }
        body {
            background: rgba(163, 171, 190, 0.36);
            display: flex;
            justify-content: center;
            align-items: center;
        }
        * {
            box-sizing: border-box;
        }
        textarea,
        input,
        button {
            outline: none;
        }
        .window-button,
        .window .buttons .close,
        .window .buttons .minimize,
        .window .buttons .maximize {
            padding: 0;
            margin: 0;
            margin-right: 4px;
            width: 12px;
            height: 12px;
            background-color: gainsboro;
            border: 1px solid rgba(0, 0, 0, 0.2);
            border-radius: 6px;
            color: rgba(0, 0, 0, 0.5);
        }
        .window {
            animation: bounceIn 1s ease-in-out;
        }
        .window .handle {
            height: 30px;
            background: linear-gradient(0deg, #d8d8d8, #ececec);
            border-top: 1px solid white;
            border-bottom: 1px solid #b3b3b3;
            border-top-left-radius: 5px;
            border-top-right-radius: 5px;
            color: rgba(0, 0, 0, 0.7);
            font-family: Helvetica, sans-serif;
            font-size: 13px;
            line-height: 22px;
            text-align: center;
        }
        .window .buttons {
            position: absolute;
            float: left;
            margin: 0 8px;
        }
        .window .buttons .close {
            background-color: #ff6159;
        }
        .window .buttons .minimize {
            background-color: #ffbf2f;
        }
        .window .buttons .maximize {
            background-color: #25cc3e;
        }
        .window .console {
            padding: 4px;
            background-color: black;
            opacity: 0.7;
            color: white;
            font-family: 'Source Code Pro', monospace;
            font-weight: 200;
            font-size: 14px;
            white-space: pre;
            border-bottom-left-radius: 5px;
            border-bottom-right-radius: 5px;
            overflow-y: auto;
        }
        .console {
            height:90%;
        }
        .prompt {
            color: #bde371;
        }
        .path {
            color: #5ed7ff;
        }
        .shell{
            width: 80%;
            border:0px;background:none;
            color:white;
        }
        .input{
            padding: 4px;

            background-color: black;

            opacity: 0.7;

            color: white;

            font-family: 'Source Code Pro', monospace;

            font-weight: 200;

            font-size: 14px;
            white-space:nowrap;
        }
        @keyframes blink {
            50% {
                color: transparent;
            }
        }
        @keyframes bounceIn {
            0% {
                transform: translateY(-1000px);
            }
            60% {
                transform: translateY(200px);
            }
            100% {
                transform: translateY(0px);
            }
        }
    </style>
</head>
<body>
<script src="/js/jquery-2.1.1.min.js"></script>
<div class="container">
    <div class="window">
        <div class="handle">
            <div class="buttons">
                <button class="close">
                </button>
                <button class="minimize">
                </button>
                <button class="maximize">
                </button>
            </div>
            <span class="title"></span>
        </div>
        <div class="input">
            <span class="prompt">➜</span>
            <span class="path">~</span>
            <input class="shell" autofocus="autofocus" type="text">
        </div>
        <div class="console"></div>
    </div>
</div>
<script>



    $(document).ready(function() {


        var h = ($(window).height());
        var w = ($(window).width());

        $(".window").css({
            "max-width":w*0.95,"max-height":h*0.95,"width":w,"height":h,"overflow-y":"auto"
        });

        var title = $(".title");
        var console = $(".console");
        var path = "~";
        var command = "";
        var url = document.URL;
        var root = url.substring(url.indexOf("//")+2,url.lastIndexOf("/"))
        var ws = new WebSocket("ws://"+root+"/msf.ws");

        var commands = [{
            "name": "clear",
            "function": clearConsole
        }];

        ws.onopen = function(evt) {
            console.append(evt.data);
        };

        ws.onmessage = function(evt) {
            if (evt.data.indexOf("c0nso1e")!=-1){
                $(".path").text(evt.data.split("##!##")[1])
            }else{
                console.append(evt.data);
            }

            var ele = $('.console')[0];
            ele.scrollTop = ele.scrollHeight;

        };

        ws.onclose = function(evt) {
            console.append("msf exit!");
        };


        function clearConsole() {
            console.text("");
        }

        function processCommand() {
            var isValid = false;
            var command = $(".shell").val();
            for (var i = 0; i < commands.length; i++) {
                if (command == commands[i].name) {
                    commands[i].function();
                    isValid = true;
                    break;
                }
            }

            if (!isValid){
                console.append("<font color='red'>msf > </font>"+command+"\n");
                ws.send(command);
            }

        }

        function sleep(numberMillis) {
            var now = new Date();
            var exitTime = now.getTime() + numberMillis;
            while (true) {
                now = new Date();
                if (now.getTime() > exitTime)
                    return;
            }
        }
        $(document).keypress(function(e) {
            e = e || window.event;
            var keyCode = typeof e.which == "number" ? e.which : e.keyCode;
            if (e.which == 13) {
                console.append("\n");
                processCommand();
                $(".shell").val("");
            }
        });

        // Set the window title
        title.text("bluer@trackray: ~ (msf)")

        // Get the date for our fake last-login
        var date = new Date().toString();
        date = date.substr(0, date.indexOf("GMT") - 1);

        // Display last-login and promt
        console.append("Last login: " + date + " on ttys000\n");
    });
</script>
</body>
</html>